Skip to content

Git shallow clone for better performance #2403

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

pukkaone
Copy link

@pukkaone pukkaone commented Apr 9, 2024

Do not download the entire commit history from the remote. Execute the equivalent of git clone --depth 1

Fixes #1544

Copy link
Member

@spencergibb spencergibb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately we can't make a change like this that changes the default existing behavior for everyone in a minor.

@spencergibb
Copy link
Member

Maybe if you make it opt in with a configuration flag

@pukkaone pukkaone force-pushed the git-shallow-clone branch from 68f2926 to d0c8281 Compare April 9, 2024 22:15
@pukkaone
Copy link
Author

pukkaone commented Apr 9, 2024

I added a configuration flag where the default is the existing behavior.

@@ -773,6 +777,9 @@ public Git getGitByOpen(File file) throws IOException {

public CloneCommand getCloneCommandByCloneRepository() {
CloneCommand command = Git.cloneRepository().setCloneSubmodules(cloneSubmodules);
if (cloneShallow) {
command.setDepth(1);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not allowing to specify a depth instead?

}

public JGitFactory(boolean cloneSubmodules) {
public JGitFactory(boolean cloneShallow, boolean cloneSubmodules) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will break compatibility with anybody calling the one parameter constructor. Also, I would put cloneShallow first. It should be the second parameter.

By default, the server clones the entire commit history from a remote
repository.  Downloading a huge commit history might be slow, so add a
configuration property to truncate the commit history to a few commits.

Fixes spring-cloud#1544
@pukkaone pukkaone force-pushed the git-shallow-clone branch from d0c8281 to a5786c0 Compare June 6, 2025 05:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Shallow clone for better performance
5 participants